<h1><?php __d('lil_media', 'View File'); ?></h1>
<?php
	echo $this->Html->css('/lil_media/css/lil_media');
?>
<div id="ViewMedia">
<?php
	$path_parts = pathinfo($base_path . DS . $filename);
	
	$icon = '';  $item_url = ''; $item_class = '';
	$item_title = $www_dir . $path_parts['basename'];
	
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
		$icon = $this->Html->image($www_dir . $path_parts['basename']);
		$item_url = $www_dir . $path_parts['basename'];
		$item_class = ' lil-media-view-image';
	} else if (in_array(strtolower($path_parts['extension']), array('doc', 'docx'))) {
		$icon = $this->Html->image('/lil_media/img/doc.gif');
	} else if (in_array(strtolower($path_parts['extension']), array('xls', 'xlsx'))) {
		$icon = $this->Html->image('/lil_media/img/xls.gif');
	} else if (strtolower($path_parts['extension']) == 'pdf') {
		$icon = $this->Html->image('/lil_media/img/pdf.gif');
	} else {
		$icon = $this->Html->image('/lil_media/img/x.gif');
	}
	
	if (empty($item_url)) {
		$item_url = array(
			'admin'  => true,
			'action'   => 'download',
			'path'     => (!empty($this->params['named']['path'])) ?
				$this->params['named']['path'] : null,
			'filename' => base64_encode($path_parts['basename'])
		);
	}
		
	echo '<div id="ViewMediaItem">';
	echo $this->Html->link(
		$icon,
		$item_url,
		array(
			'escape' => false,
			'class'  => 'lil-media-view-item' . $item_class,
			'title'  => $item_title
		)
	);
	echo '</div>';
	
	echo '<div class="view_media_item_row">';
	echo '<span class="label">' . __d('lil_media', 'Filename', true) . ': </span>';
	echo $this->Html->link(
		$path_parts['basename'],
		array(
			'admin'  => true,
			'action' => 'download',
			'path'   => (!empty($this->params['named']['path'])) ?
				$this->params['named']['path'] : null,
			'filename'   => base64_encode($path_parts['basename'])
		)
	);
	echo '</div>';
	
	echo '<div class="view_media_item_row">';
	echo '<span class="label">' . __d('lil_media', 'Path', true) . ': </span>';
	echo '<span class="value">' . $www_dir . '</span>';
	echo '</div>';
	
	echo '<div class="view_media_item_row">';
	echo '<span class="label">' . __d('lil_media', 'File size', true) . ': </span>';
	echo '<span class="value">' . $this->Number->toReadableSize($data['size']) . '</span>';
	echo '</div>';
	
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
		$dims = getimagesize($full_path . DS . $filename);
		echo '<div class="view_media_item_row">';
		echo '<span class="label">' . __d('lil_media', 'Dimensions', true) . ': </span>';
		echo '<span class="value">' . sprintf(__d('lil_media', '%1$s x %2$s px', true), $dims[0], $dims[1]) . '</span>';
		echo '</div>';
	}
?>
</div>
<?php
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
	
	echo $this->Html->css('/lil_media/css/fancybox/jquery.fancybox-1.3.1');
	echo $this->Html->script('/lil_media/js/jquery-1.4.2.min');
	echo $this->Html->script('/lil_media/js/jquery.fancybox-1.3.1.pack');
?>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".lil-media-view-image").fancybox();
		});
	</script>
<?php
	}
?>